package com.scuec.groupfive.service.impl;

import com.scuec.groupfive.entity.PostComment;
import com.scuec.groupfive.mapper.PostCommentMapper;
import com.scuec.groupfive.service.PostCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PostCommentServiceImpl implements PostCommentService {
    @Autowired
    private PostCommentMapper postCommentMapper;

    @Override
    public int getTotalCommentCount() {
        return postCommentMapper.getTotalCommentCount();
    }

    @Override
    public int getCommentCountByPostId(Long postId) {
        return postCommentMapper.getCommentCountByPostId(postId);
    }

    @Override
    public int getCommentCountByDateRange(Date startDate, Date endDate) {
        // 调整结束日期为当天23:59:59
        endDate = new Date(endDate.getTime() + 24 * 60 * 60 * 1000 - 1);
        return postCommentMapper.getCommentCountByDateRange(startDate, endDate);
    }

    @Override
    public List<PostComment> getCommentsByPostId(Long postId, int page, int size) {
        int offset = page * size;
        return postCommentMapper.getCommentsByPostId(postId, offset, size);
    }

    @Override
    public boolean deleteComment(Long commentId) {
        return postCommentMapper.deleteComment(commentId) > 0;
    }

    @Override
    public void deleteCommentsByPostId(Long postId) {
        postCommentMapper.deleteCommentsByPostId(postId);
    }
    @Override
    public boolean restoreComment(Long commentId) {
        int result = postCommentMapper.restoreComment(commentId);
        return result > 0;
    }

}